﻿<Window x:Class="DataBinding.CheckBoxList"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="CheckBoxList" Height="300" Width="300"
    >
  <Window.Resources>
    <Style x:Key="CheckBoxListStyle" TargetType="{x:Type ListBox}">
      <Setter Property="SelectionMode" Value="Multiple"></Setter>
      <Setter Property="ItemContainerStyle">
        <Setter.Value>
          <Style TargetType="{x:Type ListBoxItem}" >            
            <Setter Property="Margin" Value="2" />
            <Setter Property="Template">
              <Setter.Value>
                <ControlTemplate TargetType="{x:Type ListBoxItem}">
                
                    <CheckBox 
											IsChecked="{Binding Path=IsSelected,RelativeSource={RelativeSource TemplatedParent},Mode=TwoWay}"
											>
                      <ContentPresenter></ContentPresenter>
                    </CheckBox>
                
                </ControlTemplate>
              </Setter.Value>
            </Setter>
          </Style>
        </Setter.Value>
      </Setter>
    </Style>
  </Window.Resources>

  <Grid Margin="8">
    <Grid.RowDefinitions>
      <RowDefinition></RowDefinition>
      <RowDefinition Height="Auto"></RowDefinition>
    </Grid.RowDefinitions>
    <ListBox Style="{StaticResource CheckBoxListStyle}" Name="lstProducts"
             DisplayMemberPath="ModelName">
    </ListBox>
    <Button Grid.Row="1" Margin="0,5,0,0" Click="cmdGetSelectedItems">Get Selected Items</Button>
  </Grid>
</Window>
